package name.vaccari.matteo.tai.lezione08;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class RandomNumberServlet extends HttpServlet {

	private final NumberGenerator numberGenerator;

	public RandomNumberServlet() {
		this.numberGenerator = new RandomNumberGenerator();
	}

	public RandomNumberServlet(NumberGenerator numberGenerator) {
		this.numberGenerator = numberGenerator;
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int number = numberGenerator.getNumber();
		PrintWriter writer = resp.getWriter();
		writer.print("" + number);
		writer.close();
	}

}
